向服务器发送更多数据帧,可以多次调用write
向同一个stream
写入数据帧。
function Coroutine\Http2\Client->write(int $streamId, mixed $data, bool $end = false);
$streamId
流编号,由send
方法返回$data
数据帧的内容,可以为字符串或数组$end
是否关闭流
- 如果要使用
write
分段发送数据帧,必须在send
请求时将$request->pipeline
设置为true
- 当发送
end
为true
的数据帧之后,流将关闭。之后不能再调用write
向此stream
发送数据
use Swoole\Coroutine as co;
co::create(function () use ($fp)
{
$cli = new co\Http2\Client('127.0.0.1', 9518);
$cli->set([ 'timeout' => 1]);
var_dump($cli->connect());
$req3 = new co\Http2\Request;
$req3->path = "/index.php";
$req3->headers = [
'host' => "localhost",
"user-agent" => 'Chrome/49.0.2587.3',
'accept' => 'text/html,application/xhtml+xml,application/xml',
'accept-encoding' => 'gzip',
];
$req3->pipeline = true;
$req3->method = "POST";
$streamId = $cli->send($req3);
$cli->write($streamId, ['int' => rand(1000, 9999)]);
$cli->write($streamId, ['int' => rand(1000, 9999)]);
//end stream
$cli->write($streamId, ['int' => rand(1000, 9999), 'end' => true], true);
var_dump($cli->recv());
$cli->close();
});